package cn.swust.designpatternlearningplatform.controller;

import cn.swust.designpatternlearningplatform.common.AnnotationUtils.Authentication;
import cn.swust.designpatternlearningplatform.common.Result.R;
import cn.swust.designpatternlearningplatform.common.utils.AuthUserContext;
import cn.swust.designpatternlearningplatform.domain.dto.TestPaperDto;
import cn.swust.designpatternlearningplatform.domain.dto.StudentPersonalTrainingPaperDto;
import cn.swust.designpatternlearningplatform.domain.dto.StudentPersonalTrainingResultDto;
import cn.swust.designpatternlearningplatform.domain.enums.RoleEnum;
import cn.swust.designpatternlearningplatform.service.StudentTrainingPaperService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/studentPersonalTrainingPaper")
@Authentication(RoleEnum.STUDENT)
public class StudentTrainingPaperController {
    @Resource
    private StudentTrainingPaperService studentTrainingPaperService;
    /**
     * @param trainingNumber:
    	 * @param paperName:
      * @return R<Object>
     * @author wang
     * description 学生自主训练，更具题目数随机生成练习卷
     * date 2023/4/18 17:05
     */
    @RequestMapping("/byNumber")
    public R<Object> StudentPersonalTrainingPaperByNumber(Integer trainingNumber, String paperName){
        String studentNumber= AuthUserContext.get().getNumber();
        TestPaperDto testPaperDto =studentTrainingPaperService.getTrainingPaperByNumber(trainingNumber,paperName,studentNumber);
        return R.success(testPaperDto);
    }
  /**
    * @return R<Object>
   * @author wang
   * description 展示自己组试卷的情况
   * date 2023/4/20 19:15
   */
    @RequestMapping("/getAllTrainingPaper")
    public R<Object> GetStudentPersonalAllPaper(){
        String studentNumber=AuthUserContext.get().getNumber();
        log.info(studentNumber);
        List<StudentPersonalTrainingPaperDto> list=studentTrainingPaperService.getAllTrainingPaper(studentNumber);
        log.info(list.toString());
        return R.success(list);
    }
    /**
     * @param paperNumber:
      * @return R<Object>
     * @author wang
     * description 返回自己组卷的结果
     * date 2023/4/20 20:50
     */
    @RequestMapping("/getTestPaperContent")
    public R<Object> GetStudentPersonTrainingPaper(String paperNumber,String type){
        String studentNumber=AuthUserContext.get().getNumber();
        if (type.equals("训练卷")){
            return R.success(studentTrainingPaperService.getStudentPersonalTraining(paperNumber,studentNumber));
        }
        else {
          return R.success(studentTrainingPaperService.getTestPaperResult(paperNumber,studentNumber));
        }
    }
}
